#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QPainter>
#include <QMouseEvent>
#include <vector>
#include <QPushButton>
#include <QLabel>

static const int rows = 150;//行
static const int cols = 150;//列
static const int cellSize = 5;//细胞大小

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow() override;

protected:
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void toggleCell(const QPoint &point);

private slots:
    void nextGeneration();
    void countLiveCells();
    void startGame();
    void pauseGame();
    void resetGame();
    void randomizeCells();
    void on_colorComboBox_activated(int index);

private:
    Ui::MainWindow *ui;
    QTimer *timer;
    std::vector<std::vector<bool>> cells{rows, std::vector<bool>(cols, false)};
    QPushButton *startButton;
    QPushButton *pauseButton;
    QPushButton *resetButton;

    int generationCount;
    int liveCells;
    bool isDragging = false;
    int countNeighbors(int row, int col) const;
};
#endif // MAINWINDOW_H
